package main

import (
	"fmt"
	"sync"
	"time"
)

var exit = false

func worker(wg *sync.WaitGroup) {
	defer wg.Done()
	for {
		if exit {
			break
		}
		fmt.Println("working")
		time.Sleep(time.Second)
	}
}

// 共享内存方式, 退出goroutine
func main() {

	var wg sync.WaitGroup
	go worker(&wg)
	time.Sleep(time.Second * 3)
	exit = true
	fmt.Println("over")
}
